import util.PATH as PATH

def get_features_and_labels(developers_list, bugs_msg_all, datas_ids):
	'''
	根据传进来的bugid，提取对应bug报告的文本特征和标记序列
	:param developers_list: 
	:param bugs_msg_all: 
	:param datas_ids: 
	:return: 
	'''
	features = []
	labels = []
	for index in range(len(datas_ids)):
		name = datas_ids[index]  # 取出index位置的bug_id, 作为文件名
		feature = []
		with open(PATH.path_corpus + str(name), 'r') as reader:
			for line in reader.readlines():
				feature.append(line.strip())
		features.append(' '.join(feature))
		label = bugs_msg_all[name][0]  # assign_to
		try:
			label_id = developers_list.index(label)
		except ValueError:
			pass
		labels.append(label_id)
	return features, labels

def get_index_of_features_and_labels(vocabulary, developers_list, bugs_msg_all, datas_ids):
	features = []
	labels = []
	for index in range(len(datas_ids)):
		name = datas_ids[index]  # 取出index位置的bug_id, 作为文件名
		feature = []
		with open(PATH.path_corpus + str(name), 'r') as reader:
			for line in reader.readlines():
				feature.append(vocabulary.index(line.strip()))
		if len(feature) < 400:
			feature += [0]*(400-len(feature))
		else:
			feature = feature[:400]
		features.append(feature)

		label = bugs_msg_all[name][0]  # assign_to
		try:
			label_id = developers_list.index(label)
		except ValueError:
			pass
		labels.append(label_id)
	return features, labels